package com.tour.tour.controller;

import com.tour.tour.common.Response;
import com.tour.tour.entity.Spot;
import com.tour.tour.service.SpotService;
import com.tour.tour.vo.SpotVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author YounGCY
 * @date 2023-5-16 上午 3:07
 * @description
 */
@RestController
@RequestMapping("/spots/spot")
@CrossOrigin
public class SpotController {
    
    @Resource
    private SpotService spotService;
    
    public Response add(@RequestBody Spot spot) {
        spotService.save(spot);
        return Response.success(spot.getId());
    }
    
    @GetMapping("/{id}")
    public Response queryById(@PathVariable("id") Integer id) {
        return Response.success(spotService.getById(id));
    }
    
    @PutMapping("/update")
    public Response update(@RequestBody Spot spot) {
        spotService.updateById(spot);
        return Response.success();
    }
    
//    @GetMapping("/page")
    public Response<List<SpotVO>> getPage(@RequestParam(value = "current", defaultValue = "1") Integer current) {
        return spotService.getPage(current);
    }
    
}
